﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Models.User.SetAddChildConfigModel>" %>
<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	下级配额设置
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <fieldset>
        <legend>配额设置</legend>
        <div align="center">
        <%Html.BeginForm(); %>
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td>
                    用户名:<%=Html.TextBoxFor(p => p.Serch.Name, new {@class="text100" })%>
                    </td>
                    <td>
                    所有配额:大于<%=Html.TextBoxFor(p=>p.Serch.MinCount_AllChild, new {@class="text50" }) %>
                    &nbsp;小于<%=Html.TextBoxFor(p=>p.Serch.MaxCount_AllChild, new {@class="text50" }) %>
                    </td>
                    <td>
                    可用配额:大于<%=Html.TextBoxFor(p=>p.Serch.MinCount, new {@class="text50" }) %>
                    &nbsp;小于<%=Html.TextBoxFor(p=>p.Serch.MaxCount, new {@class="text50" }) %>
                    </td>
                    <td>
                        <input type="submit" value="搜索" />
                    </td>
                </tr>
            </table>
        <%Html.EndForm(); %>
            <table border="0" cellpadding="0" cellspacing="0" class="table" width="100%">
                <tr class="th">
                    <th >用户名</th>
                    <th >类型</th>
                    <th >所有配额</th>
                    <th >可用配额</th>
                    <th >操作</th>
                </tr>
                <%
                    var trStr = new StringBuilder();  
                    var i=0;
                    var me = Model.UsersConfig.FirstOrDefault(p => p.uid == Model.LoginUid);
                    trStr.Append("<tr><td><label>自己</label></td><td>");
                    trStr.Append(Html.Label(((UserType)me.UserType).GetName()));
                    trStr.Append("</th><td>");
                    trStr.Append(Html.Label(me.AllChildCount.ToString()));
                    trStr.Append("</td><td>");
                    trStr.Append(Html.Label(me.NowChildCount.ToString()));
                    trStr.Append("</td><td></td></tr>");
                    foreach (var item in Model.UsersConfig.Where(p => p.uid != Model.LoginUid))
                    {
                        var flag=item.UserType==(short)UserType.Member;
                        trStr.Append("<tr><td>");
                        trStr.Append(Html.Hidden("hidtxt" + i, item.uid.ToString()));
                        trStr.Append(Html.Label(item.UserName));
                        trStr.Append("</td><td>");
                        trStr.Append(Html.Label(((UserType)item.UserType).GetName()));
                        trStr.Append("</th><td>");
                        trStr.Append(flag?"0":Html.TextBox("txtAllChildCount" + i, item.AllChildCount, new { @class = "input_Text text50", validate = "{range:[0,100000],messages:{range:'大于零的数字'}}", title = "所有下级配额" + item.AllChildCount, oldvalue = item.AllChildCount }).ToString());
                        trStr.Append("</td><td>");
                        trStr.Append(flag?"0":Html.Label(item.NowChildCount.ToString()).ToString());
                        trStr.Append(flag?"</td><td>":"</td><td><input type='button' value='修改'  onclick='btn_Click(" + i + ")'/>");
                        trStr.Append("</td></tr>");
                        i++;
                    }
                    var page = Model.PageInfo;
                    if (page != null && page.SunCount >= page.PageCount)
                        trStr.Append("<tr><td colspan='5'>" + Html.Pager(page.CurrPage, page.PageCount, page.SunCount, "PageInfo.CurrPage", Url.Route(new {serch=Model.Serch }),"PageInfo.PageCount") + "</td></tr>");
                     %>
                 <%=trStr %>
            </table>
        </div>
    </fieldset>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="StyleAndScript" runat="server">
<script type="text/javascript">
    function btn_Click(i) {
        var uid = $('#hidtxt' + i).val();
        var txtACC = $('#txtAllChildCount' + i);
        var txtASC = $('#txtAllSurrogaetCount' + i);
        var oldACCValue = txtACC.attr('oldvalue');
        var oldASCValue = txtASC.attr('oldvalue');
        var accValue = txtACC.val();
        var ascValue = txtASC.val();
        if (oldACCValue == accValue && oldASCValue == ascValue) {
            alert('您未做修改!');
            return;
        }
        if (!confirm("您确定要修改当前代理的配额?")) {
            return;
        }
        getJSON('<%=Url.Action("UpdateAddChildConfig","Surrogate")%>', { Uid: uid,  ACCValue: accValue, ASCValue: ascValue }, function (result) {
            if (result) {
                if (result.count > 0) {
                    alert(result.msg);
                    location.href = location.href;
                } else {
                    alert(result.msg);
                }
            }
        });
    }
</script>
</asp:Content>
